package com.tanhua.server.controller;

<<<<<<< HEAD
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserService;
import com.tanhua.vo.UserInfoVo;
=======
import com.tanhua.commons.exception.TanHuaException;
import com.tanhua.db.User;
import com.tanhua.db.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserService;
import com.tanhua.vo.UserInfoVo;
import org.springframework.beans.BeanUtils;
>>>>>>> acc7004 (第4天到第8天)
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-06 19:40
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 根据id查询userInfo信息
     * @param token
     * @param userId
     * @param huanxinId
     * @return
     */
    @GetMapping
    public ResponseEntity getUserInfo(@RequestHeader("Authorization") String token,Long userId,Long huanxinId){
//        User user = userService.getUserByToken(token);
//        if (user == null){
//            throw new TanHuaException("登录超时，请重新登陆");
//        }
        //拦截器token统一处理
        UserInfoVo userInfoVo = userService.findUserInfoById(UserHolder.getUserId());
        return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 更新用户资料
     * 用户资料 - 保存
     * @param token
     * @param userInfoVo
     * @return
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestHeader("Authorization") String token,@RequestBody UserInfoVo userInfoVo){
        userService.updateUserInfo(token,userInfoVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 更新用户头像信息
     * @param token
     * @param headPhoto
     * @return
     */
    @PostMapping("/header")
    public ResponseEntity updateHeaderImage(@RequestHeader("Authorization") String token, MultipartFile headPhoto){
        userService.updateHeaderImage(token,headPhoto);
        return ResponseEntity.ok(null);
    }
}
